import React, { useEffect, useState } from 'react';
import { Table } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { connect } from 'umi';

interface DataType {
  key: string;
  creditRequired: number;
  gpa: number;
  classRank: number;
  majorRank: number;
}

const columns: ColumnsType<DataType> = [
  {
    title: '累计所获学分',
    dataIndex: 'creditRequired',
    key: 'creditRequired',
  },
  {
    title: '累计学分绩点',
    dataIndex: 'gpa',
    key: 'gpa',
  },
  {
    title: '班级排名',
    dataIndex: 'classRank',
    key: 'classRank',
  },
  {
    title: '专业排名',
    key: 'majorRank',
    dataIndex: 'majorRank',
  },
];

const CourseGrades: React.FC<any> = (props: any) => {
  const [data, setData] = useState<DataType[]>([]);
  useEffect(() => {
    if (props.dispatch) {
      props.dispatch({
        //路径：model的namespace+effects函数名
        type: 'Model_StudentAnalysisStudentModel/getGradeSummaryRankEffects',
        payload: {
          data: '211743',
          callback: (value: any) => {
            setData(value);
          },
        },
      });
    }
  }, []);
  return (
    <div>
      <Table
        columns={columns}
        dataSource={data}
        pagination={{ hideOnSinglePage: true }}
      />
    </div>
  );
};

export default connect(({ Model_SecondExampleModel }: any) => ({
  Model_SecondExampleModel,
}))(CourseGrades);
